/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.xuexiang.xuidemo;

import ohos.aafwk.content.Intent;

import com.xuexiang.xuidemo.ability.BaseStatusAbility;
import com.xuexiang.xuidemo.slice.SplashScreenAbilitySlice;
import com.xuexiang.xuidemo.util.RPResultListener;
import com.xuexiang.xuidemo.util.RuntimePermissionUtil;
import com.xuexiang.xuidemo.util.XToastUtils;

/**
 * 欢迎页面的Ability
 *
 * @since 2021-03-24
 */
public class MainAbility extends BaseStatusAbility {
    private static final int ONEZEROZERO = 100;

    /**
     * onStart
     *
     * @param intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(SplashScreenAbilitySlice.class.getName()); // MainAbilitySlice
    }

    /**
     * onRequestPermissionsFromUserResult
     *
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    @Override
    public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == ONEZEROZERO) {
            RuntimePermissionUtil.onRequestPermissionsResult(grantResults, new RPResultListener() {
                @Override
                public void onPermissionGranted() {
                }

                /**
                 * onPermissionDenied
                 */
                @Override
                public void onPermissionDenied() {
                    XToastUtils.error("权限申请被拒绝：ohos.permission.READ_MEDIA，ohos.permission.WRITE_MEDIA");
                }
            });
        }
    }
}
